import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;


public class FileAccessTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		
		if (args == null || args.length < 1) {
			System.err.println("Usages: java FileAccessTest file_path");
			return;
		}
			
		File f = new File(args[0]);
		System.out.println("file: " + f.getName());
		System.out.println("exists? " + f.exists());
		System.out.println("can read? " + f.canRead());
		System.out.println("can write? " + f.canWrite());
		System.out.println("is file? " + f.isFile());
		
		InputStream is = null;
		try {
			is = new FileInputStream(f);
			
		} catch (IOException e) {
			System.err.println(e);
			System.err.println("====================");
			System.err.println(e.getMessage());
		} finally {
			if (is != null)
				is.close();
		}
	}
	
	private static void validateLocation(String path)
	{
		File file = new File(path);
		try {
			if (!file.exists() || !file.isDirectory()) {
				System.err.println(path + " not exist or not a directory");
			}
			else {
				System.out.println(path + " is a directory!");
			}
		} catch (Exception e) {
			System.err.println("Exception occurred checking the path " + path + ": " + e);
		}		
	}

}
